import java.util.ArrayList;  
import java.util.List;  
import java.util.Scanner;  



class Scheduler {
    List<Process> readyQueue = new ArrayList<>();  

    public void addProcess(Process process) {  
        readyQueue.add(process);  
    }  

    public Process selectProcess() {  
        if (readyQueue.isEmpty()) {  
            return null;  
        }  

        // Sort processes by priority in descending order  
        readyQueue.sort((p1, p2) -> Integer.compare(p2.priority, p1.priority));  

        return readyQueue.get(0);  
    }  

    public void timeSlice调度() {  
        for (Process process : readyQueue) {  
            int remainingTime = process.timeSlice;  
            while (remainingTime > 0) {  
                System.out.println(process);  
                remainingTime--;  
                if (remainingTime <= 0) {  
                    readyQueue.remove(process);  
                    break;  
                }  
            }  
        }  
    }  
}  

public class Main {  
    public static void main(String[] args) {  
        Scheduler scheduler = new Scheduler();  
        Process process1 = new Process("P1", "Ready", 5, 3);  
        Process process2 = new Process("P2", "Ready", 7, 1);  
        Process process3 = new Process("P3", "Ready", 3, 2);  
        scheduler.addProcess(process1);  
        scheduler.addProcess(process2);  
        scheduler.addProcess(process3);  

        while (true) {  
            System.out.println(":");
            System.out.println("0. 返回主菜单");
            System.out.println("1. 优先级调度");  
            System.out.println("2. 时间片调度");  
            System.out.println("3. 退出");  
            Scanner scanner = new Scanner(System.in);  
            int choice = scanner.nextInt();  
            switch (choice) {  
                case 1:  
                    Process selectedProcess = scheduler.selectProcess();  
                    if (selectedProcess != null) {  
                        System.out.println("Selected process: " + selectedProcess);  
                    } else {  
                        System.out.println("No ready process found.");  
                    }  
                    break;  
                case 2:  
                    scheduler.timeSlice调度();  
                    break;  
                case 3:  
                    System.out.println("Exiting...");  
                    return;  
                default:  
                    System.out.println("Invalid choice.");  
            }  
        }  
    }  
}